<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Auth extends CI_Controller {

	public function index()
	{
		$this->load->view('auth/index');
	}
	
	public function do_login() {
		$user_id  = $this->input->post("username");
		$passwd   = $this->input->post("password");
		$this->db->where("nm_pengguna",$user_id);
		$this->db->where("password",$passwd);
        $query    = $this->db->get('tbl_pengguna');
		$count	  = $query->num_rows();
		if($count>0):
			$row  = $query->row_array();
					//$user['user_group'] = $row['group_id'];
					$user['user_name'] 	= $row['nm_pengguna'];
					$this->session->set_userdata($user);
		redirect('home',301);			
        else:
            $this->session->set_flashdata('error','<span style="color:red">Invalid username or Password  !</span>');
            redirect('/');
        endif;
	}
	
	function logout()
    {
		$this->session->sess_destroy();
		redirect('/',301);
	}
}
